//
//  UIView+Touch.m
//  Dingdong
//
//  Created by 程强 on 16/12/19.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "UIView+Touch.h"

static const void *userTouch = &userTouch;
static const void *clickView = &clickView;

@implementation UIView (Touch)
@dynamic canTouch;
@dynamic touchBlock;

- (void)setCanTouch:(NSString *)canTouch
{
    if ([canTouch isEqualToString:@"yes"]) {
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
        [self addGestureRecognizer:tap];
        self.userInteractionEnabled = YES;
    }
    objc_setAssociatedObject(self, userTouch, canTouch, OBJC_ASSOCIATION_COPY);
}
- (NSString *)canTouch
{
    return objc_getAssociatedObject(self, userTouch);
}
- (void)setTouchBlock:(ViewClickBlock)touchBlock
{
    objc_setAssociatedObject(self, clickView, touchBlock, OBJC_ASSOCIATION_COPY);
}
- (ViewClickBlock)touchBlock
{
    return objc_getAssociatedObject(self, clickView);
}
- (void)touchViewHandler:(void(^)())block
{
    self.touchBlock = block;
}
- (void)tapClick:(UITapGestureRecognizer *)tap
{
    if (self.touchBlock) {
        self.touchBlock();
    }
}
@end
